package com.chenwenxuan.sync.ui;

import java.util.ArrayList;

import javax.swing.JPopupMenu;

import com.chenwenxuan.sync.event.Event;
import com.chenwenxuan.sync.event.EventsManager;
import com.chenwenxuan.sync.event.IEventHandler;
import com.chenwenxuan.sync.event.IEventSource;

public class MenuManager extends ArrayList<AbstractAction> implements IEventSource {
	
	private static final long serialVersionUID = 3943635130768742521L;

	private EventsManager eventManager;
	
	public MenuManager(Event [] events) {
		super();
		eventManager = new EventsManager(this, events);
	}
	
	public void fullfillPopupMenu(JPopupMenu root) {
		for ( AbstractAction action : this ) {
			root.add(action);
		}
	}
	
	public void clearPopupMenu(JPopupMenu root) {
		root.removeAll();
	}
	
	
	public void raiseEvent(Event event, Object params) {
		eventManager.raiseEvent(event.getName(), params);
	}


	@Override
	public void addEventHandler(IEventHandler target, String event) {
		eventManager.addEventHandler(target, event);
	}


	@Override
	public void removeEventHandler(IEventHandler target, String event) {
		eventManager.removeEventHandler(target, event);
	}


	@Override
	public String getId() {
		return "3943635130768742521L";
	}
	
	
	

}
